﻿/// <reference path="jquery-1.8.2.js" />
(function ($, undefined) {
    $.fn.extend({
        checked: function () {
            ///<summary>CheckBox选中功能。</summary>
            if (arguments.length == 0)
                return this.attr('checked');
            var checked = arguments[0];
            return this.each(function () {
                this.checked = checked;
            });
        },
        checkedVal: function () {
            ///<summary>CheckBox选中的值。</summary>
            var values = [];
            this.each(function () {
                if (this.checked)
                    values.push(this.value);
            });
            return values.join(',');
        },
        fixedTop: function () {
            ///<summary>如果超过当前元素，将自动滚动在最顶上。</summary>
            var src = this.offset();
            var $this = this;
            window.onscroll = function () {
                var scroll = $(document).scrollTop();
                scroll = Math.max(src.top, scroll);
                $this.css({ 'position': 'absolute', 'top': scroll + 'px' });
            }
        }
    });

    window.goto = function (url) {
        ///<summary>转向操作。</summary>
        location.href = url;
    }

    window.culture = function (lang) {
        ///<summary>资源语言。</summary>
        if (lang) {
            $.cookie('language', lang, { path: '/', expires: 365 });
            top.location = top.location;
        }
        else
            return $.cookie('language');
    }
})(jQuery);

$(function () {
    $('input[moz-checkall]').click(function () {
        $('input[name=' + $(this).attr('moz-checkall') + ']').checked(this.checked);
    });
});
